package com.eralink.unionuhfreader.util;

import com.eralink.unionuhfreader.R;

import java.util.Hashtable;

public final class ErrString {
    private static Hashtable<Integer, Integer> errCodeMap = new Hashtable<>();

    static {
        errCodeMap.put(EralinkApiErrDefinition.ErrNoError, R.string.err_no_error);
        errCodeMap.put(EralinkApiErrDefinition.ErrNotOpened, R.string.err_not_opened);
        errCodeMap.put(EralinkApiErrDefinition.ErrOpenedFailed, R.string.err_opened_failed);
        errCodeMap.put(EralinkApiErrDefinition.ErrBadArg, R.string.err_bad_arg);
        errCodeMap.put(EralinkApiErrDefinition.ErrCommunicationError, R.string.err_communication_error);
        errCodeMap.put(EralinkApiErrDefinition.ErrAlreadyOpened, R.string.err_already_opened);
        errCodeMap.put(EralinkApiErrDefinition.ErrTimeout, R.string.err_timeout);
        errCodeMap.put(EralinkApiErrDefinition.ErrNeedRetry, R.string.err_need_retry);
        errCodeMap.put(EralinkApiErrDefinition.ErrRequestFailed, R.string.err_request_failed);
        errCodeMap.put(EralinkApiErrDefinition.ErrBadResponse, R.string.err_bad_response);
        errCodeMap.put(EralinkApiErrDefinition.ErrBadReport, R.string.err_bad_report);
        errCodeMap.put(EralinkApiErrDefinition.ErrWaitNoResponse, R.string.err_wait_no_response);
        errCodeMap.put(EralinkApiErrDefinition.ErrInsufficientInputBuffer, R.string.err_insufficient_input_buffer);
    }

    public static int getErrId(final int err_code) {
        int err_id = R.string.err_unknown;
        Integer errId = errCodeMap.get(err_code);
        if (null != errId) {
            err_id = errId;
        }
        return err_id;
    }
}
